package com.longtengyuyun.ThreadPool;

import java.time.Period;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author ZhaoYunLong
 * @date 2023/7/13
 * @description
 */
public class ThreadPoolTest01 {

    static ThreadPoolExecutor executor;

    private static  void createThreadPool(){

        executor = new ThreadPoolExecutor(
                4,
                10,
                30,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>(10));

    }
    private static  void createThreadPoolTwo(){

        executor = new ThreadPoolExecutor(
                4,
                8,
                30,
                TimeUnit.SECONDS,
                new LinkedBlockingQueue<>());

    }

    public static void main(String[] args) {
//        createThreadPool();
        createThreadPoolTwo();
        for (int i = 0; i < 20; i++) {
            executor.execute(new CustomRunnable());
        }
    }


    public static class  CustomRunnable implements Runnable {

        @Override
        public void run() {
            System.out.println(Thread.currentThread().getName());
            try {
                Thread.sleep(3000);
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
